package com.cx.controller;

import com.cx.pojo.Hotel;
import com.cx.pojo.HotelComment;
import com.cx.service.impl.CommentDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class CommentController {
    @Autowired
    private CommentDao commentDao;
    @RequestMapping("saveComment")
    public void saveComment(Integer hotelId,Integer uerId,String comment,String commentDate,Integer hotelScore){
        HotelComment hotelComment = new HotelComment();
        hotelComment.setCommentDate(commentDate);
        hotelComment.setComment(comment);
        hotelComment.setUerId(uerId);
        hotelComment.setHotelId(hotelId);
        hotelComment.setHotelScore(hotelScore);
        if(hotelScore >= 4){
            hotelComment.setGoodComment(true);
        }
        commentDao.save(hotelComment);
        commentDao.updateHotelScore(hotelId);

    }
    @RequestMapping("find")
    public List<HotelComment> findCommentByHotelId(Integer id){
        commentDao.findGoodComment();
        return commentDao.findHotelCommentByHotelId(id,0);
    }
    @RequestMapping("newComment")
    public List<HotelComment> t1(Integer id){
        return commentDao.gettRecentCommentByHotelId(id);
    }
}
